﻿using System;
using System.Messaging;
using NsbMonitorClientService.QueueManager;
using NUnit.Framework;

namespace NsbMonitorClientService.Tests.QueueReader
{
    [TestFixture]
    public class can_send_message_to_queue : with_local_transactional_test_queue
    {
        protected BasicQueueSender _sut;

        [SetUp]
        public void Before()
        {
            _sut = new BasicQueueSender();
        }

        [Test]
        public void Execute()
        {

            string actual = _sut.SendMessageToQueue(LocalTestQueue1Name, "test content", "label");

            string expected = ExpectedMessageId();

            Assert.AreEqual(expected, actual, "message id not as expected");

        }

        protected string ExpectedMessageId()
        {
            DateTime? oldestTime = null;

            LocalTestQueue1.MessageReadPropertyFilter.SetAll();

            Message message = LocalTestQueue1.Receive(new TimeSpan(0));

            return message.Id;
        }
    }
}